var roleManage = function() {
	var _init = function() {
		var table = $('#table_role');
		table
				.dataTable({
					"processing" : true,
					// 开启服务器模式
					serverSide : true,
					"ajax" : {
						url : "/a/msg/order",
					},
					"autoWidth" : false,
					"columns" : [
							{
								"width" : "20%",
								"render" : function(data, type, row, meta) {
									var name="";
                                    if(row.orderProductDetail){
                                        var productName=row.orderProductDetail.productName;
                                        var productSpec=row.orderProductDetail.productSpec;
                                        var productSpec1=row.orderProductDetail.productSpec1;
                                        var productSpec2=row.orderProductDetail.productSpec2;
                                        if(productSpec2){
                                            name= productName+" "+productSpec+productSpec1+productSpec2;
                                        }else  if(productSpec1){
                                            name= productName+" "+productSpec+productSpec1;
                                        } else if(productSpec){
                                            name= productName+" "+productSpec;
                                        }else{
                                            name= productName;
                                        }
                                    }

									if(row.proSpec==null){
										return row.userName+",成功下单</br>"+name;
									}else{
										return row.userName+",成功下单</br>"+name;
									}
								}
							},
							{
								"width" : "20%",
								"data" : "orderDate"
							},
							{
								"width" : "20%",
								"data" : "status"
							},
							{
								"width" : "20%",
								"data" : "null",
								"defaultContent" : "<button type=\"button\" class=\"btn blue btn_edit_role\">查看</button>"
							} ],
					"language" : {
						"lengthMenu" : "每页显示 _MENU_ 条记录",
						"emptyTable" : "暂无数据记录",
						"info" : "显示 _START_ 至 _END_ 条数据，共 _TOTAL_ 条记录！",
						"zeroRecords" : "没有搜索到匹配记录",
						"infoEmpty" : "",
						"infoFiltered" : "",
						"processing" : ""
					},
					"destroy" : true,
					"pageLength" : 5,
					"order" : [ [ 1, "desc" ] ],
					"columnDefs" : [ {
						"orderable" : false,
						"targets" : [ 0, 2,3 ]
					}, {
						"targets" : 1,
						"render" : function(data, type, row, meta) {
							return moment(data).format('YYYY-MM-DD HH:mm');
						}
					}, {
						"targets" : 2,
						"visible": false
						/*"render" : function(data, type, row, meta) {
							return data;
						}*/
					} ],
					"dom" : "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>"
							+ "<t>" + "<'row'<'col-md-5'i><'col-md-7'>p>",
					"fnInitComplete" : function() {
					}
				});

		table.on('click', '.btn_edit_role', function(event) {
			var oData_arr = table.DataTable().rows($(this).parents("tr"))
			.data(); // 操作行对象
	var _id = oData_arr[0].id;
	var status = oData_arr[0].status;
	var type = oData_arr[0].type;
	 var form = $('#form1').serializeObject();
     var isRead = form.isread;
     if(isRead == 0){ //未读
    	 window.location.href = "/p/msg/order/reader?id="+encodeURIComponent(_id)+"&type="+type+"&status="+status;    	 
     }else{//已读
    	if(status == 2){
 		window.location.href="/p/user/order/shipments?id="+ encodeURIComponent(_id);
 	}else{
 		 if(type == 1){ //到店消费
 	 		window.location.href="/p/user/storeOrder/view1?id="+encodeURIComponent(_id); 
 	 	}else{
 	 		window.location.href="/p/user/order/view?id="+encodeURIComponent(_id); 
 	 	}
 	}
    	 
     }
     
         });
		/*$("#doQuery").on("click", function(event) {
		});*/
			
	}


	return {
		init : function() {
			_init();
		}

	};

}();

var roleForm = function() {
	// 新建表单验证
	return {
		init : function() {
		}

	};
}();

$(function() {
	roleManage.init();
	roleForm.init();
	 doSearch();
});

function doSearch(){
	 var form = $('#form1').serializeObject();
		var param = {
			"IsRead" : form.isread,
			"orderNo" : form.orderNo
		};
		$('#table_role').DataTable().search(JSON.stringify(param)).draw();
}


function beback() {
	window.location.href = "/p/msg/note";
}

function getCheck() {
	roleManage.init();
}
